package com.broada.component.flexcom.manager
{
	import com.broada.component.flexcom.entity.AreaGroup;
	import com.broada.component.flexcom.entity.AreaItem;
	import com.broada.component.flexcom.entity.PointItem;
	import com.degrafa.Surface;
	
	import flash.utils.Dictionary;

	public class MapManager
	{
		private static var _instance:MapManager;
		
		private var _surface:Surface;
		private var _onShowList:Dictionary;
		
		public function MapManager()
		{
			_onShowList = new Dictionary();
		}
		
		public static function getInstance():MapManager{
			if(_instance == null){
				_instance = new MapManager();
			}
			return _instance;
		}
		
		public function install(sf:Surface):void{
			_surface = sf;
		}
		
		public function addGroup(id:String, targetId:String):void{
			var item:AreaGroup = new AreaGroup(id);
			item.group.target = _surface;
			_surface.graphicsCollection.addItem(item.group);
			item.zoomEnabled = true;
			_onShowList[id] = item;
		}
		
		public function getGroup(id:String):AreaGroup{
			return _onShowList[id] is AreaGroup?_onShowList[id]:null;
		}
		
		public function addArea(id:String, targetId:String, pathData:String):void{
			var item:AreaItem = new AreaItem(id, pathData);
			if(targetId != null && targetId.length > 0 && _onShowList[targetId] is AreaGroup){
				var target:AreaGroup = _onShowList[targetId] as AreaGroup;
				target.addArea(item);
			}else{
				item.group.target = _surface;
				_surface.graphicsCollection.addItem(item.group);
				item.zoomEnabled = true;
			}
			_onShowList[id] = item;
		}
		
		public function getArea(id:String):AreaItem{
			return _onShowList[id] is AreaItem?_onShowList[id]:null;
		}
		
		public function addCircle(id:String, targetId:String, cx:Number, cy:Number, radius:Number):void{
			if(targetId != null && targetId.length > 0 && _onShowList[targetId] is AreaItem){
				var item:PointItem = new PointItem(id, cx, cy, radius);
				var target:AreaItem = _onShowList[targetId] as AreaItem;
				target.addCircle(item);
				_onShowList[id] = item;
			}
		}
		
		public function getCircle(id:String):PointItem{
			return _onShowList[id] is PointItem?_onShowList[id]:null;
		}

		public function get surface():Surface
		{
			return _surface;
		}

	}
}